package Month11.Day11;


import java.text.SimpleDateFormat;
import java.util.*;

public class Market {
    private String name;
    private String adress;

    public Market(String name, String adress) {
        this.name = name;
        this.adress = adress;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAdress() {
        return adress;
    }

    public void setAdress(String adress) {
        this.adress = adress;
    }

    public void show() {
        System.out.println("现在去地址在" + adress + "的" + name + "超市买东西>>>>>>>>>>>>>>>>>>>>>");
    }

    //会员开卡；
    List<Member> list = new ArrayList<>();

    public void kaiKa() {
        Scanner in = new Scanner(System.in);
        System.out.println("请输入你的姓名");
        String memberName = in.next();
        System.out.println("请输入你的卡号");
        String ID = in.next();
        System.out.println("请输入你的密码");
        String password = in.next();
        System.out.println("请输入你的手机号");
        String phoneNumber = in.next();
        Calendar calendar=Calendar.getInstance();
        String cardOpeningTime= new SimpleDateFormat("yyyy-MM-dd ").format(calendar.getTime());
        Member m = new Member(memberName, ID, phoneNumber, 0,password,cardOpeningTime);
        list.add(m);
        System.out.println(list);

    }
    //显示会员信息；

    public void print() {
//        for (Member member : list) {
//            System.out.println(member);
//        }
        Iterator iterator=list.iterator();
        while (iterator.hasNext()){
            Object o = iterator.next();
            System.out.println(o);
        }
    }

    //积分兑换；
    int sum=0;//总积分
    public void exchange() {
        Scanner in = new Scanner(System.in);
        System.out.println("请输入你的卡号");
        String Id1 = in.next();
        for (Member member : list)
            if (Id1.equals(member.getID())) {
                System.out.println("请输入此次消费的金额");
                int money = in.nextInt();
                member.setIntegral(money);
                System.out.println("此次的积分为：" + member.getIntegral() + "分");
                System.out.println("请输入是否需要使用兑换礼品");
                String answer = in.next();
                if (answer.equals("需要")) {
                    while (true){
                    System.out.println("请选择你需要兑换的礼品<<<<<<<1:300分兑换抽纸,2:1000分兑换血压计,3:10000分兑换iphone6,4:退出");
                    int choice = in.nextInt();
                    if (choice == 1) {
                        if (member.getIntegral() - 300 >= 0) {
                            member.setIntegral((member.getIntegral() - 300));
                            System.out.println("抽纸礼品兑换成功，剩余积分为：" + member.getIntegral() + "分");

                        } else {
                            System.out.println("您的积分不足300分，无法兑换礼品抽纸");
                        }
                    }
                    if (choice == 2) {
                        if (member.getIntegral() - 1000 >= 0) {
                            member.setIntegral((member.getIntegral() - 1000));
                            System.out.println("血压计礼品兑换成功，剩余积分为：" + member.getIntegral() + "分");

                        } else {
                            System.out.println("您的积分不足1000分，无法兑换礼品血压计");
                        }
                    }
                    if (choice == 3) {
                        if (member.getIntegral() - 10000 >= 0) {
                            member.setIntegral((member.getIntegral() - 10000));
                            System.out.println("iphone礼品兑换成功，剩余积分为：" + member.getIntegral() + "分");

                        } else {
                            System.out.println("您的积分不足10000分，无法兑换礼品iphone");
                        }

                    }if(choice==4){
                            System.out.println("退出");
                            return;
                        }
                    }

                } else {
                    sum+=member.getIntegral();
                    System.out.println("离开超市<<<<<<<<当前积分为："+sum+"分");
                }


            } else {
                System.out.println("您的卡号输入错误。请重新输入");
            }


    }//查询积分；

    public void check(){
        Scanner in=new Scanner(System.in);
        System.out.println("请输入你的会员卡号");
        String id=in.next();
        for (Member member:list)
           if (id.equals(member.getID())){
               System.out.println(member.getIntegral()+"分");
           }
        else {
               System.out.println("卡号输入错误");
           }
    }
    //修改密码
    public void changePassword(){
        Scanner in=new Scanner(System.in);
        System.out.println("请输入你的会员卡号");
        String id=in.next();
        for (Member member:list)
            if (id.equals(member.getID())){
                System.out.println("请输入您的卡号旧密码>>>>>>>>>>>");
                String oldpssword=in.next();
                if (oldpssword.equals(member.getPassword())){
                    System.out.println("请输入你的卡号新密码>>>>>>>>>>");
                    String newpassword=in.next();
                    System.out.println("密码修改成功！");
                    member.setPassword(newpassword);
                }else {
                    System.out.println("请输入你的手机号进行验证：>>>>>>>>>>>>>>>>>");
                    String iphoneNumber=in.next();
                    if (iphoneNumber.equals(member.getPhoneNumber())){
                        System.out.println("请输入你的卡号新密码>>>>>>>>>>");
                        String newpassword=in.next();
                        System.out.println("密码修改成功！");
                        member.setPassword(newpassword);
                    }else {
                        System.out.println("无法验证，无法修改密码");
                    }
                }
            }
            else {
                System.out.println("卡号输入错误");
            }


    }


}
